﻿using SvgApplication.Common;
using SvgApplication.Data.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace SvgApplication.Web.App_Start
{
    public class DatabaseInitializer
    {
        public static void InitDb()
        {
            var context = new SvgApplicationModelContainer();
          
            //if there is no admin user in the DB, add it (default admin user)
            if (!context.Users.Any(p => p.Username == "admin"))
            {
                var adminPass = HashUtils.GetHash("admin");
                User admin = new User()
                {
                    Username = "admin",
                    Password = adminPass,
                    Role = (byte)(UserRoles.Admin)
                };

                context.Users.Add(admin);
                context.SaveChanges();
            }

        }
    }
}